<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>016给组件绑定原生组件</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="root">
    <!-- 子组件想要监听父组件的事件click -->
    <!-- 这里绑定的click事件，是个自定义的事件，不生效 -->
    <child @click="handleClick"></child>

    <h6>方法二 子组件用native去监听父组件的函数</h6>
    <child @click.native="handleClick2"></child>
  </div>
  <script>
    var vm = new Vue({
      el: "#root",
      data: {

      },
      components: {
        "child": {
          template: "<div @click='handleChildClick'>child</div>",
          methods: {
            handleChildClick: function() {
              console.log("childClick");
              // 方法一：子组件想要触发自定义click事件，需要用this.$emit去触发
              this.$emit("click");
            }
          },
        }
      },
      methods: {
        handleClick: function() {
          console.log("click");
        },
        handleClick2: function() {
          alert("click22!!");
        }
      },
    })
  </script>
</body>
</html>